package edu.contoller;

import com.aliyun.oss.internal.OSSUtils;
import edu.annotations.LoginRequired;
import edu.utils.JwtUtil;
import edu.utils.OssUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/productImage")
@CrossOrigin(origins = "*",maxAge = 3600)
public class ProductImageController {

    @LoginRequired
    @RequestMapping(value = "/uploadPic",method = RequestMethod.POST,consumes = "multipart/form-data")
    public String uploadPic(MultipartFile file, HttpServletRequest request) {
        String path = JwtUtil.getClaims(request.getHeader("token")).get("id").asString() + "/";
        return OssUtil.uploadFile(file,path);
    }
}
